<?php

namespace app\api\controller;

use app\common\controller\Api;
use EasyWeChat\Factory;
/**
 * 测试
 */
class Test extends Api
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function test(){
        $config = [
            'app_id' => 'wxaa682dbb824cdbc8',
            'secret' => '00fd331b5fbebb72bf867c8bde2478a4',

            // 指定 API 调用返回结果的类型：array(default)/collection/object/raw/自定义类名
            'response_type' => 'array',

            'log' => [
                'level' => 'debug',
                'file' => __DIR__.'/wechat.log',
            ],
        ];
        $app = Factory::officialAccount($config);
        $response = $app->oauth->scopes(['snsapi_userinfo'])->redirect();
        $response->send();
        $user = $app->oauth->user();
        // $user 可以用的方法:
        echo $user->getId();  // 对应微信的 OPENID
        echo "/n";
        echo $user->getNickname(); // 对应微信的 nickname
        $user->getName(); // 对应微信的 nickname
        $user->getAvatar(); // 头像网址
        $user->getOriginal(); // 原始API返回的结果
        $user->getToken(); // access_token， 比如用于地址共享时使用
    }

    public function testreids(){
        $config = \think\Config::get('redis');
        $client = new \Predis\Client($config);
        dump($client);
        $client->set('foo','bar');
        echo $client->get('foo');
    }

}